<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redisson 分布式锁深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .feature-icon {
            transition: all 0.3s ease;
        }
        .feature-icon:hover {
            transform: scale(1.1) rotate(5deg);
        }
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #667eea;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
        .float-animation {
            animation: float 3s ease-in-out infinite;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-gradient-to-br from-purple-600 via-indigo-600 to-blue-600 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24 text-center">
            <div class="float-animation inline-block mb-6">
                <i class="fas fa-lock text-6xl opacity-80"></i>
            </div>
            <h1 class="text-5xl md:text-7xl font-bold mb-6 serif-font">
                Redisson 分布式锁
            </h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90 max-w-3xl mx-auto">
                探索企业级分布式锁解决方案的核心技术与实现原理
            </p>
            <div class="flex justify-center space-x-4">
                <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm">
                    <i class="fas fa-code mr-2"></i> Redis 原生实现
                </span>
                <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm">
                    <i class="fas fa-shield-alt mr-2"></i> 高可用保障
                </span>
                <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full text-sm">
                    <i class="fas fa-cogs mr-2"></i> 多种锁类型
                </span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-16">
        <!-- Introduction -->
        <section class="max-w-4xl mx-auto mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-6 text-gray-800 serif-font">
                    <i class="fas fa-book-open mr-3 text-indigo-600"></i>
                    什么是 Redisson？
                </h2>
                <p class="text-lg text-gray-700 leading-relaxed drop-cap">
                    Redisson 是一个在 Redis 基础上实现的 Java 驻内存数据网格（In-Memory Data Grid）。它不仅提供了分布式的 Java 常用对象，还提供了许多分布式服务。其中，分布式锁是 Redisson 最核心和最常用的功能之一。通过 Redisson，开发者可以轻松实现分布式环境下的并发控制，确保数据的一致性和系统的稳定性。
                </p>
            </div>
        </section>

        <!-- Core Features -->
        <section class="mb-16">
            <h2 class="text-4xl font-bold text-center mb-12 text-gray-800 serif-font">
                核心特性
            </h2>
            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="text-center mb-6">
                        <div class="inline-block p-4 bg-gradient-to-br from-purple-500 to-indigo-600 rounded-full feature-icon">
                            <i class="fas fa-rocket text-3xl text-white"></i>
                        </div>
                    </div>
                    <h3 class="text-xl font-bold mb-4 text-gray-800">高性能实现</h3>
                    <p class="text-gray-600 leading-relaxed">
                        基于 Redis 的高性能特性，Redisson 实现了毫秒级的锁获取和释放操作，满足高并发场景下的性能需求。
                    </p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="text-center mb-6">
                        <div class="inline-block p-4 bg-gradient-to-br from-green-500 to-teal-600 rounded-full feature-icon">
                            <i class="fas fa-shield-virus text-3xl text-white"></i>
                        </div>
                    </div>
                    <h3 class="text-xl font-bold mb-4 text-gray-800">自动续期机制</h3>
                    <p class="text-gray-600 leading-relaxed">
                        内置看门狗（Watchdog）机制，自动延长锁的过期时间，防止业务执行过程中锁意外释放。
                    </p>
                </div>
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <div class="text-center mb-6">
                        <div class="inline-block p-4 bg-gradient-to-br from-orange-500 to-red-600 rounded-full feature-icon">
                            <i class="fas fa-layer-group text-3xl text-white"></i>
                        </div>
                    </div>
                    <h3 class="text-xl font-bold mb-4 text-gray-800">丰富的锁类型</h3>
                    <p class="text-gray-600 leading-relaxed">
                        提供可重入锁、公平锁、读写锁、信号量、闭锁等多种锁类型，满足不同业务场景需求。
                    </p>
                </div>
            </div>
        </section>

        <!-- Implementation Details -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-indigo-50 to-purple-50 rounded-2xl p-8 md:p-12">
                <h2 class="text-3xl font-bold mb-8 text-gray-800 serif-font">
                    <i class="fas fa-code mr-3 text-indigo-600"></i>
                    实现原理
                </h2>
                <div class="grid md:grid-cols-2 gap-8">
                    <div class="bg-white rounded-xl p-6 shadow-md">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">
                            <i class="fas fa-terminal mr-2 text-purple-600"></i>
                            SETNX + Lua 脚本
                        </h3>
                        <p class="text-gray-600 mb-4">
                            Redisson 底层使用 Redis 的 SETNX 命令配合 Lua 脚本实现原子性操作：
                        </p>
                        <ul class="space-y-2 text-gray-600">
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>获取锁时使用 SETNX 设置键值</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>Lua 脚本保证释放锁的原子性</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>支持可重入特性</li>
                        </ul>
                    </div>
                    <div class="bg-white rounded-xl p-6 shadow-md">
                        <h3 class="text-xl font-semibold mb-4 text-gray-800">
                            <i class="fas fa-clock mr-2 text-purple-600"></i>
                            看门狗机制
                        </h3>
                        <p class="text-gray-600 mb-4">
                            自动续期机制确保长时间运行的任务不会因锁过期而出现问题：
                        </p>
                        <ul class="space-y-2 text-gray-600">
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>默认过期时间 30 秒</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>每 10 秒自动续期一次</li>
                            <li><i class="fas fa-check-circle text-green-500 mr-2"></i>释放锁时自动停止续期</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Lock Types Visualization -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-center mb-8 text-gray-800 serif-font">
                Redisson 锁类型关系图
            </h2>
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <div class="mermaid">
                    graph TD
                        A[Redisson 分布式锁] --> B[可重入锁 RLock]
                        A --> C[公平锁 FairLock]
                        A --> D[读写锁 ReadWriteLock]
                        A --> E[信号量 Semaphore]
                        A --> F[闭锁 CountDownLatch]
                        A --> G[红锁 RedLock]
                        
                        B --> B1[支持同一线程多次获取]
                        C --> C1[按请求顺序获取锁]
                        D --> D1[读锁 - 共享]
                        D --> D2[写锁 - 独占]
                        E --> E1[限制并发访问数量]
                        F --> F1[等待多个操作完成]
                        G --> G1[多节点容错]
                        
                        style A fill:#667eea,stroke:#764ba2,stroke-width:3px,color:#fff
                        style B fill:#48bb78,stroke:#38a169,stroke-width:2px,color:#fff
                        style C fill:#4299e1,stroke:#3182ce,stroke-width:2px,color:#fff
                        style D fill:#ed8936,stroke:#dd6b20,stroke-width:2px,color:#fff
                        style E fill:#9f7aea,stroke:#805ad5,stroke-width:2px,color:#fff
                        style F fill:#f56565,stroke:#e53e3e,stroke-width:2px,color:#fff
                        style G fill:#38b2ac,stroke:#319795,stroke-width:2px,color:#fff
                </div>
            </div>
        </section>

        <!-- Lock Types Details -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold text-center mb-12 text-gray-800 serif-font">
                锁类型详解
            </h2>
            <div class="space-y-6">
                <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                    <div class="bg-gradient-to-r from-green-500 to-green-600 p-4">
                        <h3 class="text-xl font-bold text-white">
                            <i class="fas fa-redo mr-2"></i> 可重入锁（RLock）
                        </h3>
                    </div>
                    <div class="p-6">
                        <p class="text-gray-700 mb-4">最常用的分布式锁类型，支持同一线程多次获取同一把锁，避免死锁问题。</p>
                        <div class="bg-gray-50 rounded-lg p-4">
                            <code class="text-sm text-gray-800">
                                RLock lock = redisson.getLock("myLock");<br>
                                lock.lock();<br>
                                // 业务逻辑<br>
                                lock.unlock();
                            </code>
                        </div>
                    </div>
                </div>

                <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                    <div class="bg-gradient-to-r from-blue-500 to-blue-600 p-4">
                        <h3 class="text-xl font-bold text-white">
                            <i class="fas fa-balance-scale mr-2"></i> 公平锁（FairLock）